package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author daiyongfei
 * <p>
 * Hystrix之全局服务降级DefaultProperties
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystrixGlobalFallbackController {

    @Resource
    private PaymentHystrixService paymentHystrixService;


    /**
     * @param id
     * @return
     * @HystrixCommand 用全局的fallback方法
     */
    @GetMapping("/consumer/payment/hystrix/timeout2/{id}")
    @HystrixCommand
    public String paymentInfoTimeOut1(@PathVariable("id") Integer id) {
        String result = paymentHystrixService.paymentInfoTimeOut1(id);
        return result;
    }


    /**
     * 全局fallback方法
     *
     * @return
     */
    public String payment_Global_FallbackMethod() {
        return "Global异常处理信息，请稍后再试，/(ㄒoㄒ)/~~";
    }

}
